/*
 * @lc app=leetcode.cn id=1331 lang=cpp
 *
 * [1331] 数组序号转换
 */

// @lc code=start
class Solution
{
public:
    vector<int> arrayRankTransform(vector<int> &arr)
    {
        if(arr.size() == 0) return vector<int>();
        vector<int> res;
        vector<int> tmp(arr);
        sort(tmp.begin(), tmp.end());
        unordered_map<int, int> m;
        int cnt = 1;
        m[tmp[0]] = cnt++;
        for (int i = 1; i < tmp.size(); i++)
        {
            while (i < tmp.size() && tmp[i] == tmp[i - 1])
                ++i;
            if (i < tmp.size())
                m[tmp[i]] = cnt++;
        }
        for (int i = 0; i < arr.size(); i++)
            res.push_back(m[arr[i]]);
        return res;
    }
};
// @lc code=end
